// pages/product/index.js

/*************************************
 * 定时锁定，触发时后台发送锁定指令 
 ************************************ */
const {dateTimeData} = require('../../../utils/dateTimer');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        countS: 0,//定时数量
        active: false,
        buttons: [{ type: 'default', text: '取消', className: 'dialogCancel' }, {type: 'primary',  text: '确定', className: 'dialogConfirm' }],
    },

    tapShowHalt: function() {
        const {endIndex} = this.data;
        this.setData({
            showHalf: true,
            endIndex: endIndex
        });
    },
    
    taplockTimeAvaibale: function(e) {
      const {value} = e.detail;
      const lockTimeAvailable = value ? 0 : 1;
      this.setData({lockTimeAvailable})
    },
    
    /**关闭半屏弹窗回调 */
    tapHalfButton: function(e) {
        const {endArray, endIndex, selectedTime} = this.data;
        this.setData({showHalf: false})
        const date = [endArray[0][endIndex[0]], endArray[1][endIndex[1]], endArray[2][endIndex[2]]].join('-');
        const time = [endArray[3][endIndex[3]], endArray[4][endIndex[4]]].join(':');
        const new_selectedTime = [date, time].join(' ');
        if (new_selectedTime && selectedTime !== new_selectedTime) {
            this.setData({active: !1})
        }
        this.setData({new_selectedTime})
    },

    initData() {
        const d = dateTimeData(new Date(Date.now() + 3600000))
        this.setData({
            endArray: d.dateTimeArray,
            endIndex: d.dateTime.slice(0,5)
        })
    },

    /**选中日期 */
    changeEndTime: function(e) {
        this.setData({
            endIndex: e.detail.value
        });
    },

    emitReslut() {
      const {new_selectedTime, lockTimeAvailable, lockTime} = this.data;
      const lockTime2 = new_selectedTime ? new Date(new_selectedTime).getTime() : lockTime;
      const eventChannel = this.getOpenerEventChannel()
      eventChannel.emit('scheduleEvent', {lockTimeAvailable, lockTime: lockTime2});
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.initData();
        const {lockTimeAvailable, lockTime} = options;
        const lockTimeText = lockTime && lockTime > 0 ? new Date(Number(lockTime)).Format() : "";
        this.setData({
          lockTime,
          lockTimeAvailable: Number(lockTimeAvailable),
          lockTimeText
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        
    },

    /**CgAIS0g5V2J0dDAACgEB
     * 生命周期函数--监听页面显示
     */
    onShow() {
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
      this.emitReslut();
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})